clear all
set seed 77007

** set working directory

use "study 2.dta"

*dropping those that failed first attention check (and were booted)
drop if check1!=1

*second attention check (retained for analysis)
rename control2_4 attention
recode attention 5=1 *=0

*demos
recode pid 1=2 2=6 3/4=4, gen(PID)
recode PID 2=1 if pidd==1
recode PID 6=7 if pidr==1
recode PID 4=3 if pidi==1
recode PID 4=5 if pidi==2

recode sex 2/3=0, gen(male)

replace age="61" if age=="sixty one"
replace age="" if age=="Ù£Ù¥"
replace age="56" if age=="1965"
replace age="51" if age=="1970"
replace age="42" if age=="1979"
replace age="41" if age=="1980"
replace age="39" if age=="1982"
replace age="37" if age=="1984"
replace age="36" if age=="1985"
replace age="34" if age=="1987"
replace age="33" if age=="1988"
replace age="31" if age=="1990"
replace age="24" if age=="1997"
replace age="23" if age=="1998"
replace age="61" if age=="612"
destring age, replace

*metoo
recode metoo1 1=3 2=2 3=1 4=2 /* unsure as midpoint */
recode metoo4_* (.=0)
recode metoo5 2=0

recode metoo1 .=1 *=0, gen(m1)
recode metoo2 .=1 *=0, gen(m2)
recode metoo3 .=1 *=0, gen(m3)
recode metoo5 .=1 *=0, gen(m5)
gen metoo_missingcount=m1+m2+m3+m5

irt hybrid (grm metoo1-metoo3) (2pl metoo5) if metoo_missingcount<2
predict metoo_latent, latent
replace metoo_latent=. if metoo_missingcount>1

*FTs
gen FTwomen=(FT_1+FT_2+FT_4+FT_6+FT_9)/5
gen FTmen=(FT_3+FT_5+FT_7+FT_8+FT_10)/5
gen FTgendiff=FTmen-FTwomen

*HSR
recode hsr4 1=5 2=4 4=2 5=1
recode hsr9 1=5 2=4 4=2 5=1
alpha hsr*, item casewise gen(HSR)
replace HSR=(HSR-1)/4
gen HSR5 = (hsr1+hsr2+hsr3+hsr4+hsr5-5)/20

*HSO
recode original1* (1=6) (2=5) (3=4) (4=3) (5=2) (6=1)
recode original2_1 (1=6) (2=5) (3=4) (4=3) (5=2) (6=1)
recode original2_2 (1=6) (2=5) (3=4) (4=3) (5=2) (6=1)
recode original2_3 (1=6) (2=5) (3=4) (4=3) (5=2) (6=1)
alpha original*, item asis casewise gen(HSO)
replace HSO=(HSO-1)/6
gen HSO5 = (original1_1+original1_2+original1_3+original1_4+original1_5-5)/25

rename original1_1 hso1
rename original1_2 hso2
rename original1_3 hso3
rename original1_4 hso4
rename original1_5 hso5
rename original2_1 hso7
rename original2_2 hso6
rename original2_3 hso8
rename original2_4 hso9
rename original2_5 hso10
rename original2_6 hso11

*creating combined scales - rescaling to empirical range of 0/1
egen HS_combined5=rowfirst(HSO5 HSR5)
gen revised=.
replace revised=1 if HSR5!=.
replace revised=0 if HSO5!=.

*timers
rename Q77_PageSubmit time_hsr1
rename Q78_PageSubmit time_hsr2
rename Q80_PageSubmit time_hso1
rename Q79_PageSubmit time_hso2
gen time_fullhsr=(time_hsr1+time_hsr2)
gen time_fullhso=(time_hso1+time_hso2)

*control
recode control1_* (1=6) (2=5) (3=4) (4=3) (5=2) (6=1)
alpha control1_*, item asis casewise gen(Control1)
alpha control2_*, item asis casewise gen(Control2)
alpha control1_* control2_*, item casewise asis gen(ControlFull)


************
* analysis *
************

*truncation
tab HSR5
tab HSO5

*reliability
alpha hsr1 hsr2 hsr3 hsr4 hsr5, item casewise asis
alpha hso1 hso2 hso3 hso4 hso5, item casewise asis

*time
sum time_hsr1, detail
sum time_hso1, detail


*figure 2
hist HSR5, xlab(0(.2)1) ylab(0(50)200) xtitle("Item-Specific Scale") freq saving(hist_is.gph, replace)
hist HSO5, xlab(0(.2)1) ylab(0(50)200) xtitle("Agree-Disagree Scale") freq saving(hist_ad.gph, replace)
graph combine hist_ad.gph hist_is.gph, subtitle("")

reg metoo_latent c.HS_combined5##i.revised PID ideo follow educ age male i.race
est store metoo5
margins, dydx(revised) at(HS_combined5=(0 1)) vsquish
margins revised, at(HS_combined5=(0(.2)1))
marginsplot, ylab(-.8(.4).8) recast(line) recastci(rarea) ciopt(color(gs10%20)) ytitle("Opposition to #MeToo") xtitle("Hostile Sexism") legend(label(1 "Agree-Disagree") label(2 "Item-Specific")) title("") subtitle("") saving(metoo5.gph, replace)
	
*predictive - FTs, differencing by gender, collapsing over party
reg FTgendiff c.HS_combined5##i.revised PID ideo follow educ age male i.race
est store ftdiff5
margins revised, at(HS_combined=(0(.2)1))
marginsplot, ylab(-5(5)15) recast(line) recastci(rarea) ciopt(color(gs10%20)) ytitle("Men - Women") xtitle("Hostile Sexism") yline(0) legend(order(3 "Agree-Disagree" 4 "Item-Specific") rows(1)) title("") subtitle("") saving(FTG5.gph, replace)
	
*graph combine for predictive validity
grc1leg metoo5.gph FTG5.gph, legendfrom(FTG5.gph) 	subtitle("")


*discriminant validity - control scale
cor HSO5 Control1 Control2
cor HSR5 Control1 Control2

*bootstrapping to test for differences
keep if HS_combined!=.
keep if ControlFull!=.

gen o5_1=.
gen o5_2=.
gen r5_1=.
gen r5_2=.

gen o11_1=.
gen o11_2=.
gen r11_1=.
gen r11_2=.

forval x=1/1000 {
preserve
bsample
qui cor HSO5 Control1
local o51=r(rho) in `x'
qui cor HSO5 Control2
local o52=r(rho) in `x'
qui cor HSR5 Control1
local r51=r(rho) in `x'
qui cor HSR5 Control2
local r52=r(rho) in `x'

qui cor HSO Control1
local o111=r(rho) in `x'
qui cor HSO Control2
local o112=r(rho) in `x'
qui cor HSR Control1
local r111=r(rho) in `x'
qui cor HSR Control2
local r112=r(rho) in `x'

restore
qui replace o5_1=`o51' in `x'
qui replace o5_2=`o52' in `x'
qui replace r5_1=`r51' in `x'
qui replace r5_2=`r52' in `x'

qui replace o11_1=`o111' in `x'
qui replace o11_2=`o112' in `x'
qui replace r11_1=`r111' in `x'
qui replace r11_2=`r112' in `x'

di `x'
}

*results for 5-item scale
sum o5* r5*
gen hso5_controldiff=o5_1-o5_2
gen hsr5_controldiff=r5_1-r5_2
sum hs*controldiff
gen controldid5=.
replace controldid5=1 if hso5_controldiff>hsr5_controldiff
replace controldid5=0 if hso5_controldiff<=hsr5_controldiff
replace controldid5=. if (hso5_controldiff==. | hsr5_controldiff==.)
tab controldid5

*results for 11-item scale
sum o11* r11*
gen hso11_controldiff=o11_1-o11_2
gen hsr11_controldiff=r11_1-r11_2
sum hs*controldiff
gen controldid11=.
replace controldid11=1 if hso11_controldiff>hsr11_controldiff
replace controldid11=0 if hso11_controldiff<=hsr11_controldiff
replace controldid11=. if (hso11_controldiff==. | hsr11_controldiff==.)
tab controldid11
